<template>
  <el-row type="flex" justify="center" align="middle">
    <el-col :span="20">
      <div style=" vertical-align: middle; text-align: center;">
        <el-divider></el-divider>
        <div style="margin-bottom: 10px;margin-top: 10px">
          <h2 style="color: #636569;" >融资企业审核</h2>
        </div>

        <el-divider></el-divider>
        <el-input
            style="margin-bottom: 10px;margin-top: 10px"
            placeholder="请输入企业名称"
            @keyup.enter.native="search()"
            v-model="input">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>

        <el-table :data="finance"   :border="true">
          <el-table-column align="center" label="企业名称" prop="enterpriseName" ></el-table-column>
          <el-table-column align="center" label="法人姓名" prop="legal" width="80px"></el-table-column>
          <el-table-column align="center" label="法人电话" prop="legalPhone"></el-table-column>
          <el-table-column align="center" label="法人证件号" prop="legalId"></el-table-column>
          <el-table-column align="center" label="营业执照号" prop="businessLicense"></el-table-column>
          <el-table-column align="center" label="注册资金" prop="registeredCapital"></el-table-column>
          <el-table-column align="center" label="企业资金" prop="businessCapital"></el-table-column>
          <el-table-column align="center" label="营业执照" prop="">
            <template slot-scope="scope">
              <div class="demo-image__preview">
              <el-image :src="scope.row.businessLicenseImage" @click="showDialog = true"> </el-image>
                <el-dialog :visible.sync="showDialog" width="80%">
                  <el-image :src="scope.row.businessLicenseImage" fit="contain"></el-image>
                </el-dialog>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="审核状态" width="80px">
            <template slot-scope="scope">
              <span>{{scope.row.coreState == 0 ? '未审核':(scope.row.coreState == 1 ?'审核通过':'审核未通过')}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="90px">
            <template slot-scope="scope">
            <el-button type="success"  @click="confirm(scope.row)">通过</el-button>
            <el-button type="warning" style="margin-top: 3px" @click="veto(scope.row)">否决</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            background
            :page-sizes="[1, 2, 4]"
            :page-size="pageSize"
            :current-page="pageNum"
            @current-change="handleCurrentChange"
            @prev-click="prevPage"
            @next-click="nextPage"
            @size-change="changePage"
            layout="total,sizes,prev, pager, next"
            :total="total">
        </el-pagination>

      </div>



    </el-col>
  </el-row>
</template>
<script>
export default {
  data(){
    return{
      coreId:'',
      pageNum:1,
      pageSize:2,
      total:0,
      list:[],
      finance:[],
      showDialog: false,
      input:'',
    }
  },
  methods: {
    //通过用户名获取核心企业id
    requestCoreId() {
      let account = localStorage.getItem('userName');
      this.$axios.get('api/user/selectUserByAccount?account=' + account,
          {headers: {'jwt': localStorage.getItem('jwt')}})
          .then(res => {
            // console.log(res.data)
            if (res.data.code == 200) {
              this.coreId = res.data.data.userCoreId;
              this.requestList()
            }
          })
    },
    //通过核心企业id获取平台推荐的融资企业id
    requestList() {
      let requestResult = {};
      requestResult.pageNum = 1;
      requestResult.pageSize = 10000;
      let data = {
        auditResult: 1,
        coreId: this.coreId
      };
      requestResult.data = data
      // console.log(requestResult)
      this.$axios.post(
          'api/CoreRecommendationRecord/selectRecommendationByCoreId',
          requestResult,
          {headers: {'jwt': localStorage.getItem('jwt')}})
          .then(res => {
            if (res.data.code == 200) {
              // console.log(res.data)
              this.PageNum = res.data.data.pageNum
              const lists = res.data.data.list
              lists.forEach(list => {
                this.list.push(list.financeId)
              })
              this.requestFinance();
            }
          })
    },
    //通过融资企业id查询融资企业信息
    requestFinance() {
      let requestResult = {};
      requestResult.pageNum = this.pageNum;
      requestResult.pageSize = this.pageSize;
      let data = this.list;
      requestResult.data = data;
      this.$axios.post(
          'api/finance/findFinanceByListId',
          requestResult,
          {headers: {'jwt': localStorage.getItem('jwt')}})
          .then(res => {
            // console.log(res.data)
            this.finance = res.data.data.list;
            this.pageNum = res.data.data.pageNum;
            this.pageSize = res.data.data.pageSize;
            this.total = res.data.data.total;
          })
    },
    //通过审核融资企业
    confirm(row) {
    console.log(row)
      row.coreState = 1;
      const finance = row;
      this.$axios.post(
          'api/finance/modifyFinance',
          finance,
          {headers: {'jwt': localStorage.getItem('jwt')}})
          .then(res => {
            // console.log(res.data)
            if(res.data.code == 200){
              this.requestFinance()
            }
          })
    },
    //拒绝审核
    veto(row){
      console.log(row)
      row.coreState = 2;
      const finance = row;
      this.$axios.post(
          'api/finance/modifyFinance',
          finance,
          {headers: {'jwt': localStorage.getItem('jwt')}})
          .then(res => {
            // console.log(res.data)
            if(res.data.code == 200){
              this.requestFinance()
            }
          })
    },
    //搜索
    search(){
      console.log("1111")
      let requestResult = {};
      requestResult.pageNum = this.pageNum;
      requestResult.pageSize = this.pageSize;
      let data = {
        enterpriseName:this.input,
        enterpriseId:this.coreId

      }
      requestResult.data = data
      this.$axios.post(
          'api/finance/findListFinanceByName',
          requestResult,
          {headers:{'jwt':localStorage.getItem('jwt')}})
          .then(res => {
            console.log(res.data)
            if(res.data.code == 200){
              this.finance = res.data.data.list;
              this.pageNum = res.data.data.pageNum;
              this.pageSize = res.data.data.pageSize;
              this.total = res.data.data.total;
            }
          })
    },
    //自己选择第几页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val
      this.requestFinance()
    },


//上一页
    prevPage(val) {
      console.log(val)
      this.pageNum = val
      this.requestFinance();
    },

//下一页
    nextPage(val) {
      this.pageNum = val
      this.requestFinance();
    },

    // 改变每页几条
    changePage(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.requestFinance();
    },

  },
  created(){
    this.requestCoreId();
  }

}
</script>
<style scoped>
.el-row {
  background-image: url("../../../assets/login/Recommend.jpg");
  background-size: 100% 100%;
  height: 100%;
}
.el-col {
  background-color: rgba(232, 241, 232, 0.46);
  padding-top: 35px;
  border-radius: 30px;
  width: 1200px;
  height: 700px;
  padding: 20px;
}
.el-button{
  width:70px;
  height: 30px;
  padding: 0;
  margin: 0 0 0 0;
}
/*最外层透明*/
/deep/ .el-table, /deep/ .el-table__expanded-cell{
  background-color: transparent;

}
/* 表格内背景颜色 */
/deep/ .el-table th,
/deep/ .el-table tr,
/deep/ .el-table td {
  background-color: transparent;
}

.el-divider{
  margin: 0;
}
</style>